<template>
    <div class="qingwu">
        <div class="admin_table_page_title">邻里圈提现配置</div>
        <div class="unline underm"></div>

        <div class="admin_table_handle_btn">
            <a-form layout="inline" :form="form">
                <a-form-item label="用户ID">
                    <a-input type="number"  v-model="user_id" placeholder="用户ID"/>
                </a-form-item>

                <a-form-item label="状态">
                    <a-select @change="handleChange" style="width: 120px" default-value="待审核" v-model="type">
                        <a-select-option :value="value.id" v-for="(value,index) in type_lists"
                                         :key="index">
                            {{ value.title }}
                        </a-select-option>
                    </a-select>
                </a-form-item>
                <a-form-model-item>
                    <a-button icon="search" @click="search">
                        查询
                    </a-button>
                </a-form-model-item>
            </a-form>
        </div>

        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false"
                     :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="id">
                <span slot="action" slot-scope="rows">
                    <a-button icon="file-search"
                              @click="$router.push('/Admin/flea_withdrawal/form/'+rows.user_id)">用户支出收入</a-button>
                    <a-button type="primary" icon="check" @click="confirm(rows.id)">通过</a-button>
                    <a-button type="danger" icon="close" @click="refuse(rows.id)">拒绝</a-button>
                </span>

            </a-table>
            <div class="admin_pagination" v-if="pages>0">
                <a-pagination v-model="params.page" :page-size.sync="params.limit" :total="pages" @change="onChange"
                              show-less-items/>
            </div>
        </div>

        <a-modal v-model="visible" title="拒绝理由" @ok="handleOk" cancelText="取消" okText="确定">
            <a-form-model-item>
                <a-input v-model="mark" type="textarea"/>
            </a-form-model-item>
        </a-modal>
    </div>
</template>

<script>
    export default {
        components: {},
        props: {},
        data() {
            return {
                params: {
                    page: 1,
                    limit: 20,
                },
                id: '',
                visible: false,
                pages: 0, //总页数
                mark: '',
                state: 1,
                user_id: '',
                selectedRowKeys: [], // 被选择的行
                columns: [
                    {title: '#', dataIndex: 'id', fixed: 'left'},
                    {title: '用户ID', dataIndex: 'user_id'},
                    {title: '提现金额', dataIndex: 'money'},
                    {title: '提现状态', dataIndex: 'state_text'},
                    {title: '提现时间', dataIndex: 'created_at'},
                    {title: '审核时间', dataIndex: 'examine_at'},
                    {title: '拒绝理由', dataIndex: 'mark'},
                    {title: '操作', key: 'id', fixed: 'right', scopedSlots: {customRender: 'action'}},
                ],
                list: [],
                type: 1,
                type_lists: [{id: 1, title: '待审核'}, {id: 2, title: '通过'}, {id: 3, title: '拒绝'}]
            };
        },
        watch: {},
        computed: {},
        methods: {
            // 选择框被点击
            onSelectChange(selectedRowKeys) {
                this.selectedRowKeys = selectedRowKeys;
            },
            handleOk() {
                //如果是拒绝 必须写入理由
                if (this.state == 2 && this.$isEmpty(this.mark)) {
                    return this.$message.error('请填写理由');
                }
                let param = {id: this.id, state: this.state, mark: this.mark};
                this.$post(this.$api.fleaWithdrawal, param).then(res => {
                    if (res.code == 200) {
                        this.onload();
                        this.$message.success('成功');
                        this.visible = false;
                    } else {
                        this.$message.error(res.msg)
                    }
                });
            },
            // 选择分页
            onChange(e) {
                this.params.page = e;
                this.onload();
            },
            onload() {
                this.$get(this.$api.fleaWithdrawal, this.params).then(res => {
                    this.pages = res.data.pages;
                    this.list = res.data.data;
                });
            },
            //拒绝
            refuse(id) {
                if (!id) {
                    return this.$message.error('未选择数据');
                }
                //拒绝
                this.state = 2;
                this.id = id
                this.visible = true;
            },
            confirm(id) {
                if (!id) {
                    return this.$message.error('未选择数据');
                }
                //拒绝
                this.state = 1;
                this.id = id
                //发送通过请求
                this.handleOk()
            },
            // 搜索
            search() {
                this.params['user_id'] = this.user_id;
                this.params['state'] = this.type;
                this.$get(this.$api.fleaWithdrawal, this.params).then(res => {
                    this.pages = res.data.pages;
                    this.list = res.data.data;
                });
            },
        },
        created() {
            this.onload();
        },
        mounted() {
        }
    };
</script>
<style lang="scss" scoped>

</style>
